---------------------------------------------------------------------------------------------------- -- mob_trader ---------------------------------------------------------------------------------------------------- local global_animations = { desk_idle = {"idle","idle_1","palci","zatylok"}, --desk_talk = {"idle"}, desk_to_chair_hack = {"idle_spinka"}, desk_to_listen = {"idle_chitaet"}, desk_to_diagonal = {"perehod_0"}, chair_hack_idle = {"idle_2","idle_2_def_0"}, chair_hack_talk = {"idle_2_talk_0","idle_2_talk_1","idle_2_talk_2","idle_2_talk_3"}, chair_hack_to_diagonal = {"idle_2_to_idle_0"}, chair_hack_to_desk = {"spinka_idle"}, compute_idle = {"idle_1_spec_think_0","idle_1_spec_think_1"}, compute_idle_to_diagonal = {"idle_1_to_idle_0"}, diagonal_idle = {"idle_0_def_0","idle_0_spec_click_0","idle_0_spec_scratch_0"}, diagonal_idle_short = {"idle_0_def_0"}, diagonal_talk = {"idle_0_talk_0","idle_0_talk_1","idle_0_talk_2","idle_0_talk_3"}, diagonal_to_chair_hack = {"idle_0_to_idle_2"}, diagonal_to_compute = {"idle_0_to_idle_1"}, diagonal_to_desk = {"perehod_1"}, --first_phrase = {"vstuplenie"}, listen_idle = {"chitaet"}, listen_to_desk = {"chitaet_idle"}, hello = {"hello"}, forester_sit = {"sit"}, forester_beard = {"beard_in","beard","beard_out"}, forester_reaction = {"reaction_in","reaction","reaction_out"}, forester_see = {"see_in","see","see_out"}, forester_talk_1 = {"sit_talk_1_in","sit_talk_1","sit_talk_1_out"}, forester_talk_2 = {"sit_talk_2_in","sit_talk_2","sit_talk_2_out"}, forester_talk_3 = {"sit_talk_3_in","sit_talk_3","sit_talk_3_out"} } local head_animations = { forester_talk_1 = {"sit_talk_1_in","sit_talk_1","sit_talk_1_out"}, forester_talk_2 = {"sit_talk_2_in","sit_talk_2","sit_talk_2_out"}, forester_talk_3 = {"sit_talk_3_in","sit_talk_3","sit_talk_3_out"}, forester_reaction = {"reaction_in","reaction","reaction_out"}, normal = {"talk_0","talk_1","talk_4"}, angry = {"talk_3","talk_2","talk_1"}, good = {"talk_glad_0"}--, -- first_phrase = {"vstuplenie_head"} } class "mob_trader" function mob_trader:__init(obj, storage) self.object = obj self.st = storage end function mob_trader:reset_scheme() local trader_obj = self.object -- xr_logic.mob_capture(trader_obj, true) --self.st.signals = {} trader_obj:set_callback(callback.trader_global_anim_request, self.on_global_anim_request, self ) trader_obj:set_callback(callback.trader_head_anim_request, self.on_head_anim_request, self ) trader_obj:set_callback(callback.trader_sound_end, self.on_sound_end, self ) trader_obj:set_callback(callback.use_object, self.use_callback, self) -- start global animation trader_obj:set_trader_global_anim(self:select_global_animation()) -- start sound and head animation if (self.st.sound_phrase) then if tostring(self.st.sound_phrase):find("_trade",1,true) then if math.random(100) > 40 then local snd = mob_sound.pick_sound_from_set(self.st.sound_phrase) self.object:set_trader_sound(snd, self:select_head_animation()) end else local snd = mob_sound.pick_sound_from_set(self.st.sound_phrase) trader_obj:set_trader_sound(snd, self:select_head_animation()) end end if self.st.anim_head == nil then self.st.anim_head = "normal" end self.st.signals = {} db.trader = trader_obj end --[[ function mob_trader:use_callback() end --]] function mob_trader:update(delta) if xr_logic.try_switch_to_another_section(self.object, self.st, db.actor) then return end end --------------------------------------------------------------------------------------------------------------------- function mob_trader:select_global_animation() local anim_set = global_animations[self.st.anim_global] --local r = math.random(1, #anim_set) if anim_set then return anim_set[math.random(1,#anim_set)] --/> random select end abort("Can't find anim '%s' for trader in table global_animations",self.st.anim_global) --return anim_set[r] end function mob_trader:select_head_animation() -- random select local anim_set = head_animations[self.st.anim_head] --local r = math.random(1, #anim_set) if anim_set then return anim_set[math.random(1,#anim_set)] --/> random select end abort("Can't find anim '%s' for trader in table head_animations",self.st.anim_head) --return anim_set[r] end --------------------------------------------------------------------------------------------------------------------- function mob_trader:on_global_anim_request() self.st.signals["animation_end"] = true if (not self.st.play_once) then self.object:set_trader_global_anim(self:select_global_animation()) end end function mob_trader:on_head_anim_request() if self.st.anim_head == nil then return end self.object:set_trader_head_anim(self:select_head_animation()) end function mob_trader:on_sound_end() self.st.signals["sound_phrase_end"] = true end --------------------------------------------------------------------------------------------------------------------- function mob_trader:deactivate() self.object:set_callback(callback.trader_global_anim_request, nil ) self.object:set_callback(callback.trader_head_anim_request, nil ) self.object:set_callback(callback.trader_sound_end, nil ) self.object:set_callback(callback.use_object, nil ) -- self.st.signals = {} db.trader = nil self.object:set_tip_text("") self.object:set_tip_text_default() -- if xr_logic.mob_captured(self.object) then -- xr_logic.mob_release(self.object) -- end end function mob_trader:net_destroy() self:deactivate() end --------------------------------------------------------------------------------------------------------------------- function add_to_binder(npc, ini, scheme, section, storage) --printf("DEBUG: add_to_binder: npc:name()='%s', scheme='%s', section='%s'", npc:name(), scheme, section) local new_action = mob_trader(npc, storage) -- Зарегистрировать все actions, в которых должен быть вызван метод reset_scheme при изменении настроек схемы: xr_logic.subscribe_action_for_events(npc, storage, new_action) end function set_scheme(npc, ini, scheme, section)--, gulag_name) --printf("_bp: mob_trader: set_scheme") local st = xr_logic.assign_storage_and_bind(npc, ini, scheme, section) st.logic = xr_logic.cfg_get_switch_conditions(ini, section, npc) st.anim_global = ini:r_string_ex(section,"anim_global") st.can_talk = ini:r_bool_ex(section,"can_talk",true) st.tip_text = ini:r_string_ex(section,"tip_text") or "character_use" if st.tip_text == nil then st.tip_text = "" end npc:set_tip_text(st.tip_text) if (ini:line_exist( section, "sound_phrase")) then st.anim_head = ini:r_string_ex(section,"anim_head") st.sound_phrase = ini:r_string_ex(section,"sound_phrase") else st.anim_head = nil st.sound_phrase = nil end --' check if play once animation st.play_once = false if (ini:line_exist( section, "on_signal")) then local str = ini:r_string_ex(section,"on_signal") local par = utils_data.parse_params(str) if par[1] == "animation_end" then st.play_once = true end end if st.can_talk == true then npc:enable_talk() else npc:disable_talk() end end